<template>
  <el-dialog :visible.sync="visible" v-dialogDrag="true" :title="title" :close-on-click-modal="false"  width="1200px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-row class="province-post">
        <el-col :span="10">
          <el-form-item label="省区" prop="deptcommoncode1" :rules="rules.validateRequire">
            <el-select v-model="model.deptcommoncode1" filterable clearable>
              <el-option v-for="item in codeModel.deptcommoncode1List" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col class="marketing-post-selection" :span="12">
          <el-form-item label="行销岗位" prop="marketingpost" :rules="rules.validateRequire">
            <el-select v-model="model.marketingpost" filterable clearable @click.native="doQueryCode" ref="refmarketingpost">
              <el-option v-for="item in codeModel.marketingpostList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="2">
          <el-button type="primary" icon="el-icon-plus" @click="$refs[123].visible = true">
            <tl-add-post ref="123" ></tl-add-post>
          </el-button>
        </el-col>
      </el-row>
      <el-row v-model="model.postpostusername">
        <el-col :span="24">
          <el-form-item label="岗位人员" prop="postpostusernames" :rules="rules.validateRequire">
            <tl-ref-user v-model="model.postusercodes" dataType="code" :initDisplayData.sync="model.postpostusernames"> </tl-ref-user>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="岗位人员工号" prop="postusercodes" :rules="rules.validateRequire">
            <el-input class="readOnlyInputInner" v-model="model.postusercodes" :readonly="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="对接产品线" >
            <el-select v-model="productlines" filterable multiple clearable>
              <el-option v-for="item in codeModel.productLineList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
            <el-popover style="float: right;margin-right: -20px;" title="对接产品线" width="300"  placement="top" trigger="click" >
              主要应用于行销查看对应产品线MO在资料中心上传的资料使用。
              <span slot="reference"><i class="el-icon-info" ></i></span>
            </el-popover>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" :rows="2"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="排序码" prop="sortcode">
            <el-input-number v-model="model.sortcode" controls-position="right" :step="1" :min="0" style="width:100%"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="有效" prop="enabled">
            <el-radio-group v-model="model.enabled">
              <el-radio :label="parseInt(item.code)" v-for="item in codeModel.enabledList" :key="item.code">{{ item.name }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from "@tapui/mixins/mixin_edit"
import tlAddPost from "./addPostDialog"
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from "@tapui/utils/http"
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: { tlAddPost },
  data() {
    return {
      moduleTitle: "省区行销配置信息表",
      urlPrefix: "/mms/provinceMarketingInfo/",
      url: {
      },
      productlines: []
    }
  },
  methods: {
    open() {
      this.model = {}
      this.productlines = []
      this.$nextTick(() => {
          this.$refs.form.clearValidate()
          if (this.isAdd === true) {
              this.title = '添加' + this.moduleTitle
              if (this.isQueryInitData === true) {
                  // 后台进行数据初始化
                  this.queryInitData().then((_) => {
                      this.assignDefaultValue()
                      this.loaded()
                  })
              } else {
                  // 前台进行数据初始化
                  this.$set(this.model, 'enabled', 1)
                  this.$set(this.model, 'sortcode', 0)
                  this.assignDefaultValue()
                  this.loaded()
              }
          } else if (this.disableEditSubmit === false) {
              this.title = '编辑' + this.moduleTitle
              this.queryData(this.id).then((_) => {
                  this.loaded()
              })
          } else {
              this.title = '查看' + this.moduleTitle
              this.queryData(this.id).then((_) => {
                  this.loaded()
              })
          }
      })
    },
    loaded() {
      // 页面加载完毕执行
      if (this.model.productline && this.model.productline !== '') {
          this.productlines = this.model.productline.split(',')
      } else {
          this.productlines = []
      }
    },
    beforeSubmit() {
        this.model.productline = this.productlines.join(',')
        if (this.productlines.length === 0) {
          this.$tap.alert('请填写对接产品线！')
          return false
        }
        return true
    }
  }
}
</script>
<style lang="scss" scoped>
.readOnlyInputInner /deep/ .el-input__inner {
  background-color: #F5F7FA
}
.province-post{
.marketing-post-selection {
  width: 54.1%;
}
.el-col-2{
  width: 4%;

}
}
</style>
